<?php

namespace app\admin\controller;

use app\admin\service\LinksService;
use support\spark\model\system\WebsiteLinks;
use support\Request;
use support\View;

/**
 *友情链接控制器
 */
class LinksController extends Curd
{
    /**
     * 获取列表
     */
    public function index()
    {
        if (request()->isAjax()) {
            $linksService = new LinksService();
            $res = $linksService->getList(request()->all());
            return sparkSuccess($res);
        }
        return view('links/index');
    }

    /**
     * 添加
     */
    public function add()
    {
        if (request()->isAjaxPost()) {
            $param = request()->post();
            $linksService = new LinksService();
            $res = $linksService->addLinks($param);
            return sparkSuccess($res);
        }
        return view('links/add');
    }

    /**
     * 编辑
     */
    public function edit()
    {
        if (request()->isAjaxPost()) {
            $param = request()->post();

            $linksService = new LinksService();
            $res = $linksService->editLinks($param);
            return sparkSuccess($res);
        }

        $id = request()->input('id');
        $websiteLinksModel = new WebsiteLinks();
        View::assign([
            'info' => $websiteLinksModel->getInfoByWhere([
                'id' => $id
            ])
        ]);

        return view('links/edit');
    }

    /**
     * 删除
     */
    public function del()
    {
        $id = request()->input('id');

        $websiteLinksModel = new WebsiteLinks();
        $websiteLinksModel->delById($id);
        return sparkSuccess(dataReturn(0,'删除成功'));
    }

}